﻿using LogManager;
using org.h2.tools;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;

namespace H2TcpServer
{
    public partial class Service1 : ServiceBase
    {
        private Server server = null;
        public Service1()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            Logger.Info("H2tcp 服务开始启动...");
            try
            {
                Server server = Server.createTcpServer("-tcp","-tcpPort", "9092", "-tcpAllowOthers").start();
                Logger.Info("H2tcp 服务启动成功！");
            }
            catch (Exception ex)
            {

                Logger.Fatal("H2tcp 服务启动失败！\t\n" + ex.ToString());
            }
        }

        protected override void OnStop()
        {
            if(server != null)
            {
                server.stop();
                Logger.Info("H2tcp 服务已停止！");
            }
        }
    }
}
